/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package py.una.informatica.facades;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import py.una.informatica.entidades.Paciente;

/**
 *
 * @author MARTINCHO
 */
@Stateless
public class PacienteFacade extends AbstractFacade<Paciente> {
    @PersistenceContext(unitName = "py.com.konecta_EmergenciasEJB_ejb_1.0-SNAPSHOTPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public PacienteFacade() {
        super(Paciente.class);
    }
    
    public Paciente getPacienteById (Long idPaciente){
        Paciente per = null;
        try{
            getEntityManager().getEntityManagerFactory().getCache().evictAll();
            TypedQuery<Paciente> query = getEntityManager().createNamedQuery("Paciente.findByIdPaciente", Paciente.class);
            per = query.setParameter("idPaciente", idPaciente).getSingleResult();
            
        }catch (Exception ex){
            ex.printStackTrace();
        }
        return per;
    }
    
        public Paciente getPacienteByCedula (Integer cedula){
        Paciente per = null;
        try{
            getEntityManager().getEntityManagerFactory().getCache().evictAll();
            TypedQuery<Paciente> query = getEntityManager().createNamedQuery("Paciente.findByNumDoc", Paciente.class);
            per = query.setParameter("numDoc", cedula).getSingleResult();
            
        }catch (Exception ex){
            ex.printStackTrace();
        }
        return per;
    }
    
}
